package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domainVo.TCwCheckBatchDetailVo;
import com.ruoyi.service.impl.TCwCheckBatchDetailServiceImpl;
import org.junit.Test;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.domain.TCwCheckBatchDetail;
import com.ruoyi.service.ITCwCheckBatchDetailService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 对账批次明细Controller
 * 
 * @author ruoyi
 * @date 2023-02-27
 */
@RestController
@RequestMapping("/detail")
public class TCwCheckBatchDetailController extends BaseController
{
    @Autowired
    private ITCwCheckBatchDetailService tCwCheckBatchDetailService;

    /**
     * 查询对账批次明细列表
     */
    @RequiresPermissions("detail:detail:list")
    @PostMapping("/list")
    public TableDataInfo list( TCwCheckBatchDetailVo tCwCheckBatchDetail)
    {
        startPage();
        List<TCwCheckBatchDetail> list = tCwCheckBatchDetailService.selectTCwCheckBatchDetailList(tCwCheckBatchDetail);

        return getDataTable(list);
    }

    /**
     * 导出对账批次明细列表
     */
    @RequiresPermissions("detail:detail:export")
    @Log(title = "对账批次明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCwCheckBatchDetailVo tCwCheckBatchDetail)
    {
        List<TCwCheckBatchDetail> list = tCwCheckBatchDetailService.selectTCwCheckBatchDetailList(tCwCheckBatchDetail);
        ExcelUtil<TCwCheckBatchDetail> util = new ExcelUtil<TCwCheckBatchDetail>(TCwCheckBatchDetail.class);
        util.exportExcel(response, list, "对账批次明细数据");
    }

    /**
     * 获取对账批次明细详细信息
     */
    @RequiresPermissions("detail:detail:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tCwCheckBatchDetailService.selectTCwCheckBatchDetailById(id));
    }

    /**
     * 新增对账批次明细
     */
    @RequiresPermissions("detail:detail:add")
    @Log(title = "对账批次明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCwCheckBatchDetail tCwCheckBatchDetail)
    {
        return toAjax(tCwCheckBatchDetailService.insertTCwCheckBatchDetail(tCwCheckBatchDetail));
    }

    /**
     * 差错处理  金额不一致
     */
    @RequiresPermissions("detail:detail:edit")
    @Log(title = "对账批次明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCwCheckBatchDetail tCwCheckBatchDetail)
    {
        return toAjax(tCwCheckBatchDetailService.updateTCwCheckBatchDetail(tCwCheckBatchDetail));
    }

    /**
     *
     * @param tCwCheckBatchDetail
     * @return
     */
    @RequiresPermissions("detail:detail:edit")
    @Log(title = "对账批次明细", businessType = BusinessType.UPDATE)
    @PostMapping("editCheckBatchDetail")
    public AjaxResult updetaCheckBatchDetail(@RequestBody TCwCheckBatchDetail tCwCheckBatchDetail)
    {

        int i= tCwCheckBatchDetailService.updateTCwCheckBatchDetails(tCwCheckBatchDetail);
        return toAjax(i);
    }
    /**
     * 删除对账批次明细
     */
    @RequiresPermissions("detail:detail:remove")
    @Log(title = "对账批次明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCwCheckBatchDetailService.deleteTCwCheckBatchDetailByIds(ids));
    }

    /**
     * 查询对账批次明细与对账交易流水是否一致
     * @param tCwCheckBatchDetail
     */
    @RequiresPermissions("detail:detail:query")
    @PutMapping("selectDetailByOrder")
    public AjaxResult selectDetailByOrder(@RequestBody TCwCheckBatchDetail tCwCheckBatchDetail){
       TCwCheckBatchDetail Detail= tCwCheckBatchDetailService.selectDetailByOrder(tCwCheckBatchDetail);
        return  AjaxResult.success();
    }
/*    @Test
    public  void test() {
        TCwCheckBatchDetailVo tCwCheckBatchDetail=new TCwCheckBatchDetailVo();
        List<TCwCheckBatchDetail> tCwCheckBatchDetails = tCwCheckBatchDetailService.selectTCwCheckBatchDetailList(tCwCheckBatchDetail);
        for (TCwCheckBatchDetail cwCheckBatchDetail : tCwCheckBatchDetails) {
            String payOrderNo = cwCheckBatchDetail.getPayOrderNo();
            if(payOrderNo!=null){
                String substring = payOrderNo.substring(0);
                System.out.println(substring);
            }

        }

    }*/
}
